<template>
  <div class="app-container home">
    <span
      >公告编辑：(传图、视频文件等功能不能使用，只能简单的文案及链接跳转，链接配置方式：先敲链接文字，再点功能区倒数第三个按钮添加跳转地址)</span
    >
    <div style="margin-top: 20px">
      <Editor v-model="content" :minHeight="300"></Editor>
    </div>

    <el-button style="margin-top: 20px" :loading="loading" type="primary" @click="updateHandler">确认更新</el-button>
  </div>
</template>

<script setup name="Dashboard">
import Editor from "@/components/Editor/index.vue";
import { getSystemApi, updateSystemApi } from "@/api/base/index.js";
import { ElMessage } from "element-plus";

const content = ref("");
const loading = ref(false);

const getData = async () => {
  loading.value = true;
  const res = await getSystemApi().finally(() => {
    loading.value = false;
  });

  content.value = res.content;
};

const updateHandler = async () => {
  loading.value = true;
  await updateSystemApi(content.value).finally(() => {
    loading.value = false;
  });
  ElMessage.success("更新成功");
};

getData();
</script>
